package com.quanyan.travel.service.impl;

import com.google.gson.Gson;
import com.quanyan.travel.api.RespOutdoorActivity;
import com.quanyan.travel.entity.TbOutdoorActivity;
import com.quanyan.travel.entity.vo.MultiMedia;
import com.quanyan.travel.mapper.TbOutdoorActivityMapper;
import com.quanyan.travel.service.TravelOpenService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dongshenglin
 * @date 2016/7/13  10:13
 */
@Service("travelOpenService")
public class TravelOpenServiceImpl implements TravelOpenService {

    @Autowired
    private TbOutdoorActivityMapper tbOutdoorActivityMapper;

    @Override
    public List<RespOutdoorActivity> getOutdoorActivityListByids(List<Integer> ids) {
        List<RespOutdoorActivity> respOutdoorActivityList = new ArrayList<>();
        if (null != ids && ids.size() >0 ){
            for (Integer id : ids){
                TbOutdoorActivity tbOutdoorActivity = tbOutdoorActivityMapper.selectByPrimaryKey(id);
                if(tbOutdoorActivity!=null){
                    RespOutdoorActivity respOutdoorActivity = new RespOutdoorActivity();
                    BeanUtils.copyProperties(tbOutdoorActivity,respOutdoorActivity);
                    //活动图片
                    Gson gson = new Gson();
                    MultiMedia multiMedia = gson.fromJson(tbOutdoorActivity.getMultiMedia(), MultiMedia.class);
                    if (multiMedia.getType() == 0) {
                        respOutdoorActivity.setImageUrl(multiMedia.getImage().getImageUrl());
                    } else if (multiMedia.getType() == 1) {
                        respOutdoorActivity.setImageUrl(multiMedia.getVideo().getImageUrl());
                    }
                    respOutdoorActivityList.add(respOutdoorActivity);
                }
            }
        }
        return respOutdoorActivityList;
    }

}
